package main

import "fmt"
import "time"

// 生成了三个消息：{[hello Goroutine! 1], [hello Goroutine! 2], [hello Goroutine! 3]}
// 消费的时候按FIFO进行消费
var message = make(chan string, 3)

func sample1() {
	message <- "hello Goroutine! 1"
	message <- "hello Goroutine! 2"
	message <- "hello Goroutine! 3"
}

func sample2() {
	time.Sleep(2*time.Second)
	str := <-message
	str = str + "I'm goroutine"
	message <- str
}

func main() {
	go sample1()
	go sample2()
	time.Sleep(3*time.Second)
	fmt.Println(<-message)
	fmt.Println(<-message)
	fmt.Println(<-message)
	fmt.Println("Hello World!")
}
